/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.matrimonysite.sessionbean;

import com.matrimonysite.entity.UserProfile;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author khanhnguyen
 */
@Stateless
public class UserProfileFacade extends AbstractFacade<UserProfile> {

    @PersistenceContext(unitName = "MatrimonySite-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public UserProfileFacade() {
        super(UserProfile.class);
    }

    @Override
    public void create(UserProfile profile) {
        em.persist(profile);
    }

    @Override
    public void edit(UserProfile profile) {
        em.merge(profile);
    }

    @Override
    public void remove(UserProfile profile) {
        em.remove(em.merge(profile));
    }

    public UserProfile getProfileID(String profileID) {
        UserProfile profile = null;
        try {
            Query q = em.createNamedQuery("UserProfile.findByProfileID");
            q.setParameter("profileID", profileID);
            profile = (UserProfile) q.getSingleResult();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return profile;
    }

    public UserProfile getFirstname(String firstname) {
        UserProfile profile = null;
        try {
            Query q = em.createNamedQuery("UserProfile.findByFirstname");
            q.setParameter("firstname", firstname);
            profile = (UserProfile) q.getSingleResult();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return profile;
    }

    public UserProfile getMiddleName(String middlename) {
        UserProfile profile = null;
        try {
            Query q = em.createNamedQuery("UserProfile.findByMiddleName");
            q.setParameter("middlename", middlename);
            profile = (UserProfile) q.getSingleResult();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return profile;
    }

    public UserProfile getLastName(String lastname) {
        UserProfile profile = null;
        try {
            Query q = em.createNamedQuery("UserProfile.findByLastName");
            q.setParameter("lastname", lastname);
            profile = (UserProfile) q.getSingleResult();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return profile;
    }

    public UserProfile getGender(String gender) {
        UserProfile profile = null;
        try {
            Query q = em.createNamedQuery("UserProfile.findByGender");
            q.setParameter("gender", gender);
            profile = (UserProfile) q.getSingleResult();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return profile;
    }

    public UserProfile getDateOfBirth(String dateofbirth) {
        UserProfile profile = null;
        try {
            Query q = em.createNamedQuery("UserProfile.findByDateOfBirth");
            q.setParameter("dateofbirth", dateofbirth);
            profile = (UserProfile) q.getSingleResult();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return profile;
    }

    public UserProfile getMaritalStatus(String maritalstatus) {
        UserProfile profile = null;
        try {
            Query q = em.createNamedQuery("UserProfile.findByMaritalStatus");
            q.setParameter("maritalstatus", maritalstatus);
            profile = (UserProfile) q.getSingleResult();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return profile;
    }

    public UserProfile getHeight(String height) {
        UserProfile profile = null;
        try {
            Query q = em.createNamedQuery("UserProfile.findByHeight");
            q.setParameter("height", height);
            profile = (UserProfile) q.getSingleResult();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return profile;
    }

    public UserProfile getCity(String city) {
        UserProfile profile = null;
        try {
            Query q = em.createNamedQuery("UserProfile.findByCity");
            q.setParameter("city", city);
            profile = (UserProfile) q.getSingleResult();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return profile;
    }

    public UserProfile getCountryLiving(String countryliving) {
        UserProfile profile = null;
        try {
            Query q = em.createNamedQuery("UserProfile.findByCountryLiving");
            q.setParameter("countryliving", countryliving);
            profile = (UserProfile) q.getSingleResult();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return profile;
    }

    public UserProfile getMotherTongue(String mothertongue) {
        UserProfile profile = null;
        try {
            Query q = em.createNamedQuery("UserProfile.findByMotherTongue");
            q.setParameter("mothertongue", mothertongue);
            profile = (UserProfile) q.getSingleResult();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return profile;
    }

    public UserProfile getContactNumber(String contactnumber) {
        UserProfile profile = null;
        try {
            Query q = em.createNamedQuery("UserProfile.findByContactNumber");
            q.setParameter("contactnumber", contactnumber);
            profile = (UserProfile) q.getSingleResult();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return profile;
    }

    public UserProfile getReligion(String religion) {
        UserProfile profile = null;
        try {
            Query q = em.createNamedQuery("UserProfile.findByReligion");
            q.setParameter("religion", religion);
            profile = (UserProfile) q.getSingleResult();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return profile;
    }

    public UserProfile getCaste(String caste) {
        UserProfile profile = null;
        try {
            Query q = em.createNamedQuery("UserProfile.findByCaste");
            q.setParameter("caste", caste);
            profile = (UserProfile) q.getSingleResult();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return profile;
    }

    public UserProfile getVisited(String visited) {
        UserProfile profile = null;
        try {
            Query q = em.createNamedQuery("UserProfile.findByVisited");
            q.setParameter("visited", visited);
            profile = (UserProfile) q.getSingleResult();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return profile;
    }
    
    public List<UserProfile> getAllUserProfile(){
        Query query= em.createNamedQuery("UserProfile.findAll");
        return query.getResultList();
    }
}
